package com.code.man.util;

import com.code.man.model.ColumnInfo;
import com.google.common.base.CaseFormat;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author 167786
 * @date 2019/9/30 18:48
 */
public class FreeMarkerExtUtils {
    public static List<String> getImportTypeByColumn(List<ColumnInfo> columnInfoList) {
        Set<String> set = new HashSet<>();
        for (ColumnInfo columnInfo : columnInfoList) {
            // 过滤掉lang下的包
            if (!columnInfo.getJavaType().contains("java.lang.")) {
                set.add(columnInfo.getJavaType());
            }
        }
        return new ArrayList<>(set);
    }

    public static List<String> getDbNameListByColumn(List<ColumnInfo> columnInfoList) {
        return columnInfoList.stream().map(m -> m.getDbName()).collect(Collectors.toList());
    }

    public static String getSimpleTypeName(String fullTypeName) {
        if (StringUtils.isBlank(fullTypeName)) {
            return "";
        }

        int lastDot = fullTypeName.lastIndexOf('.');
        if (lastDot >= 0) {
            return fullTypeName.substring(lastDot + 1);
        }

        return fullTypeName;
    }

    public static String getUpperCamel(String str) {
        return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, str);
    }

    public static String getlowerCamel(String str) {
        return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, str);
    }

    public static String getLowerFirst(String str) {
        return StringUtils.uncapitalize(str);
    }

    public static String getUpperFirst(String str) {
        return StringUtils.capitalize(str);
    }
}
